package dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

  
    
  
/**
 * This class was autogenerated by Torque on:
 *
 * [Fri Jan 09 02:39:32 PST 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to StudentDegree
 */
public abstract class BaseStudentDegree extends BaseObject
{
    /** The Peer class */
    private static final StudentDegreePeer peer =
        new StudentDegreePeer();

        
    /** The value for the studentdegreeid field */
    private int studentdegreeid;
      
    /** The value for the studentid field */
    private int studentid;
      
    /** The value for the degreeid field */
    private int degreeid;
  
    
    /**
     * Get the Studentdegreeid
     *
     * @return int
     */
    public int getStudentdegreeid()
    {
        return studentdegreeid;
    }

                        
    /**
     * Set the value of Studentdegreeid
     *
     * @param v new value
     */
    public void setStudentdegreeid(int v) 
    {
    
                  if (this.studentdegreeid != v)
              {
            this.studentdegreeid = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Studentid
     *
     * @return int
     */
    public int getStudentid()
    {
        return studentid;
    }

                              
    /**
     * Set the value of Studentid
     *
     * @param v new value
     */
    public void setStudentid(int v) throws TorqueException
    {
    
                  if (this.studentid != v)
              {
            this.studentid = v;
            setModified(true);
        }
    
                          
                if (aStudent != null && !(aStudent.getStudentid() == v))
                {
            aStudent = null;
        }
      
              }
  
    /**
     * Get the Degreeid
     *
     * @return int
     */
    public int getDegreeid()
    {
        return degreeid;
    }

                              
    /**
     * Set the value of Degreeid
     *
     * @param v new value
     */
    public void setDegreeid(int v) throws TorqueException
    {
    
                  if (this.degreeid != v)
              {
            this.degreeid = v;
            setModified(true);
        }
    
                          
                if (aDegreeCourse != null && !(aDegreeCourse.getDegreeid() == v))
                {
            aDegreeCourse = null;
        }
      
              }
  
      
    
                  
    
        private Student aStudent;

    /**
     * Declares an association between this object and a Student object
     *
     * @param v Student
     * @throws TorqueException
     */
    public void setStudent(Student v) throws TorqueException
    {
            if (v == null)
        {
                    setStudentid(0);
                  }
        else
        {
            setStudentid(v.getStudentid());
        }
                aStudent = v;
    }

                                            
    /**
     * Get the associated Student object
     *
     * @return the associated Student object
     * @throws TorqueException
     */
    public Student getStudent() throws TorqueException
    {
        if (aStudent == null && (this.studentid > 0))
        {
                          aStudent = StudentPeer.retrieveByPK(SimpleKey.keyFor(this.studentid));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               Student obj = StudentPeer.retrieveByPK(this.studentid);
               obj.addStudentDegrees(this);
            */
        }
        return aStudent;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setStudentKey(ObjectKey key) throws TorqueException
    {
      
                        setStudentid(((NumberKey) key).intValue());
                  }
    
    
                  
    
        private DegreeCourse aDegreeCourse;

    /**
     * Declares an association between this object and a DegreeCourse object
     *
     * @param v DegreeCourse
     * @throws TorqueException
     */
    public void setDegreeCourse(DegreeCourse v) throws TorqueException
    {
            if (v == null)
        {
                    setDegreeid(0);
                  }
        else
        {
            setDegreeid(v.getDegreeid());
        }
                aDegreeCourse = v;
    }

                                            
    /**
     * Get the associated DegreeCourse object
     *
     * @return the associated DegreeCourse object
     * @throws TorqueException
     */
    public DegreeCourse getDegreeCourse() throws TorqueException
    {
        if (aDegreeCourse == null && (this.degreeid > 0))
        {
                          aDegreeCourse = DegreeCoursePeer.retrieveByPK(SimpleKey.keyFor(this.degreeid));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               DegreeCourse obj = DegreeCoursePeer.retrieveByPK(this.degreeid);
               obj.addStudentDegrees(this);
            */
        }
        return aDegreeCourse;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setDegreeCourseKey(ObjectKey key) throws TorqueException
    {
      
                        setDegreeid(((NumberKey) key).intValue());
                  }
       
                
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("Studentdegreeid");
              fieldNames.add("Studentid");
              fieldNames.add("Degreeid");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("Studentdegreeid"))
        {
                return new Integer(getStudentdegreeid());
            }
          if (name.equals("Studentid"))
        {
                return new Integer(getStudentid());
            }
          if (name.equals("Degreeid"))
        {
                return new Integer(getDegreeid());
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(StudentDegreePeer.STUDENTDEGREEID))
        {
                return new Integer(getStudentdegreeid());
            }
          if (name.equals(StudentDegreePeer.STUDENTID))
        {
                return new Integer(getStudentid());
            }
          if (name.equals(StudentDegreePeer.DEGREEID))
        {
                return new Integer(getDegreeid());
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getStudentdegreeid());
            }
              if (pos == 1)
        {
                return new Integer(getStudentid());
            }
              if (pos == 2)
        {
                return new Integer(getDegreeid());
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(StudentDegreePeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    StudentDegreePeer.doInsert((StudentDegree) this, con);
                    setNew(false);
                }
                else
                {
                    StudentDegreePeer.doUpdate((StudentDegree) this, con);
                }
            }

                      alreadyInSave = false;
        }
      }


                    
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  studentdegreeid ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
            setStudentdegreeid(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
            setStudentdegreeid(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getStudentdegreeid());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public StudentDegree copy() throws TorqueException
    {
        return copyInto(new StudentDegree());
    }
  
    protected StudentDegree copyInto(StudentDegree copyObj) throws TorqueException
    {
          copyObj.setStudentdegreeid(studentdegreeid);
          copyObj.setStudentid(studentid);
          copyObj.setDegreeid(degreeid);
  
                    copyObj.setStudentdegreeid(0);
                        
        
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public StudentDegreePeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("StudentDegree:\n");
        str.append("Studentdegreeid = ")
           .append(getStudentdegreeid())
           .append("\n");
        str.append("Studentid = ")
           .append(getStudentid())
           .append("\n");
        str.append("Degreeid = ")
           .append(getDegreeid())
           .append("\n");
        return(str.toString());
    }
}
